package project.Mapper;

import org.apache.ibatis.annotations.*;
import project.Pojo.WordCount;

import java.util.List;

@Mapper
public interface WordMapper {

    @Delete("delete from word_count where user_name=#{username}")
    int deleteByUserName(String username);

    @Insert("INSERT INTO word_count (user_name,word,count,updated_at) VALUES (#{username},#{word},#{count},NOW())")
    int insert(WordCount wordCount);

    @Select("SELECT user_name, word, count, updated_at FROM word_count WHERE user_name = #{username} ORDER BY count DESC LIMIT 10")
    @Results({
            @Result(property = "username", column = "user_name"),
            @Result(property = "word", column = "word"),
            @Result(property = "count", column = "count"),
            @Result(property = "updateTime", column = "updated_at")
    })
    List<WordCount> selectTopWordsByUserName(String username);
}
